import javax.media.opengl.GL;

import com.sun.opengl.util.GLUT;


public class Queen extends GameObject implements VisibleObject
{
	private GLUT glut;
	private double targetX,targetY,targetZ;
	private double dx,dy,dz,absDX,absDZ,speedFactor;
	private boolean relocate;
	
	public Queen(double xIn, double yIn, double zIn)
	{
		setLocationX(xIn);
		setLocationY(yIn);
		setLocationZ(zIn);
		speedFactor = 0.1;
		relocate = false;
		glut = new GLUT();
	}
	
	public void setTarget(int xIn, int zIn)
	{
		//targetX = (xIn+0.5)*World.SQUARE_SIZE;
		//targetZ = (zIn+0.5)*World.SQUARE_SIZE;
		relocate = true;
	}
	
	public void display(GL gl)
	{
		if(relocate)
		{			
			dx = (targetX - locationX);			
			dz = (targetZ - locationZ);
			
			absDX = Math.abs(dx);
			absDZ = Math.abs(dz);
			
			if((absDX+absDZ)<1)
			{
				//dig a hole
				World.complete=true;
				World.siteX = World.getGrid(locationX);
				World.siteZ = World.getGrid(locationZ);
				relocate=false;
			}
			else
			{
				if(absDX>absDZ)
				{
					dx/=absDX;
					dz/=absDX;
				}
				else
				{
					dx/=absDZ;
					dz/=absDZ;
				}
				targetY= World.HEIGHT_MAP[World.getGrid(locationX+dx)][World.getGrid(locationZ+dz)]+3;
				dy = (targetY - locationY)*speedFactor;
				
				dx*=speedFactor;
				dz*=speedFactor;
				locationX+=dx;
				locationZ+=dz;	
				locationY += dy;
			}
			
		}
		
		gl.glPushMatrix();
			gl.glTranslated(locationX, locationY, locationZ);
			glut.glutSolidSphere(0.5, 10, 10);
		gl.glPopMatrix();
	}
}
